define(['config'],()=>{
    require(['jquery'],()=>{
        class Header{
            constructor(){
                this.loadHtml()
            }
            loadHtml(){
                $('header').load('/html/includes/header.html',()=>{
                    let user=localStorage.getItem('username')
                    if(user){
                        $('.render')[0].innerHTML=`
                            欢迎您！<span>${user}</span>
                            &emsp;
                            <span class='quit'>退出登录</span>
                        `  
                        let list = JSON.parse(localStorage.getItem('cart')) || []
                        let num = 0
                        list.forEach(item=>{
                            num += item.cart_number
                        })
                        $('.numHeader')[0].innerHTML= '&nbsp;'+num
                    }else{
                        $('.render')[0].innerHTML=`
                        <span class="login">登录</span>
                        或
                        <span class="reg">注册</span>
                        ANTA会员
                        `
                    }
                    $('.login').on('click',()=>{
                        location.href='/html/login.html'
                    })
                    $('.reg').on('click',()=>{
                        location.href='/html/reg.html'
                    })
                    $('.icon-gouwucheman').on('click',()=>{
                        location.href='/html/cart.html'
                    })
                    $('.quit').on('click',()=>{
                        localStorage.removeItem('username')
                        this.loadHtml()
                    })
                })
            }
        }
        return new Header()
    })
})